﻿using System;
using Fjaspx.Common;
using System.Data;
using System.Web.UI.WebControls;

namespace Fjaspx.UI.Web
{
    /// <summary>
    /// 
    /// </summary>
    public partial class TEACHER_edit_edit : System.Web.UI.Page
    {

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SystemCms.AdminSesion();
                if (Fjaspx.Common.Session.Get("user_id") == null)
                {
                    Response.Redirect("~/UCenter/login.aspx");
                }
                else
                {
                    //DdlMenu_bind();
                    ShowInfo(Convert.ToInt32(Fjaspx.Common.Session.Get("user_id")));
                }
            }
        }

        /// <summary>
        /// Shows the info.
        /// </summary>
        /// <param name="user_id">The user_id.</param>
        private void ShowInfo(int user_id)
        {
            Fjaspx.Sys.Bll.ROYcms_Enterprise bll = new Fjaspx.Sys.Bll.ROYcms_Enterprise();
            Fjaspx.Sys.Model.ROYcms_Enterprise model = bll._GetModel(user_id);
            if (model != null)
            {
                try
                {
                    this.lb_name.Text = model.gs_name;

                    this.TextBox_keyword.Text = model.keyword;
                    this.TextBox_description.Text = model.description;


                   // this.DdlMenu.SelectedValue = model.classname.ToString();

                    this.txtgs_name.Text = model.gs_name;
                    this.txtgs_address.Text = model.gs_address;
                    this.txtgs_tel.Text = model.gs_tel;
                    this.txtgs_web.Text = model.gs_web;
                    this.txtgs_email.Text = model.gs_email;

                    FCK_1.Value = model.introduces;
                    FCK_2.Value = model.business_scope;
                    FCK_3.Value = model.contacts_us;
                    FCK_4.Value = model.intelligence_honor;

                    FCK_5.Value = model.enterprise_culture;
                    FCK_6.Value = model.marketing_network;
                    FCK_7.Value = model.other_1;
                    FCK_8.Value = model.other_2;
                    FCK_9.Value = model.other_3;
                    FCK_10.Value = model.other_4;
                }
                catch { Response.Write("show异常！");
                Fjaspx.Common.SystemCms.InsertErrLog("SHOW错误！", Request.PhysicalPath);
                }
            }
            else {
                try
                {
                    Enterprise_add();
                }
                catch { Response.Write("Enterprise_add异常！");
                Fjaspx.Common.SystemCms.InsertErrLog("Enterprise_add异常！", Request.PhysicalPath);
                }
            }

        }

        /// <summary>
        /// Handles the Click event of the btnUpdate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public void btnUpdate_Click(object sender, EventArgs e)
        {
            int user_id =0;
            if (Fjaspx.Common.Session.Get("user_id") == null) {
                Response.Redirect("~/UCenter/login.aspx");
            }
            else{
                user_id = Convert.ToInt32(Fjaspx.Common.Session.Get("user_id"));
            }

            string keyword = Fjaspx.Common.input.Htmls(TextBox_keyword.Text);
            string description = Fjaspx.Common.input.Htmls(TextBox_description.Text);

            int classname = int.Parse("00");
            string gs_name = Fjaspx.Common.input.Htmls(txtgs_name.Text);
            string gs_address = Fjaspx.Common.input.Htmls(txtgs_address.Text);
            string gs_tel = Fjaspx.Common.input.Htmls(txtgs_tel.Text);
            string gs_web = Fjaspx.Common.input.Htmls(txtgs_web.Text);
            string gs_email = Fjaspx.Common.input.Htmls(txtgs_email.Text);

            string introduces = Fjaspx.Common.input.Htmls(FCK_1.Value);
            string business_scope = Fjaspx.Common.input.Htmls(FCK_2.Value);
            string contacts_us = Fjaspx.Common.input.Htmls(FCK_3.Value);
            string intelligence_honor = Fjaspx.Common.input.Htmls(FCK_4.Value);

            string enterprise_culture = Fjaspx.Common.input.Htmls(FCK_5.Value);
            string marketing_network = Fjaspx.Common.input.Htmls(FCK_6.Value);
            string other_1 = Fjaspx.Common.input.Htmls(FCK_7.Value);
            string other_2 = Fjaspx.Common.input.Htmls(FCK_8.Value);
            string other_3 = Fjaspx.Common.input.Htmls(FCK_9.Value);
            string other_4 = Fjaspx.Common.input.Htmls(FCK_10.Value);


            Fjaspx.Sys.Model.ROYcms_Enterprise model = new Fjaspx.Sys.Model.ROYcms_Enterprise();
            model.user_id = user_id;
            if (keyword == "")
            {
                model.keyword = gs_name;
            }
            else { model.keyword = keyword; }

            if (description == "")
            {
                model.description = gs_name;
            }
            else { model.description = description; }

            model.classname = classname;

            model.gs_name = gs_name;
            model.gs_tel = gs_tel;
            model.gs_web = gs_web;
            model.gs_email = gs_email;
            model.gs_address = gs_address;


            model.introduces = introduces;
            model.business_scope = business_scope;
            model.intelligence_honor = intelligence_honor;
            model.contacts_us = contacts_us;
            model.enterprise_culture = enterprise_culture;
            model.marketing_network = marketing_network;
            model.other_1 = other_1;
            model.other_2 = other_2;
            model.other_3 = other_3;
            model.other_4 = other_4;


            Fjaspx.Sys.Bll.ROYcms_Enterprise bll = new Fjaspx.Sys.Bll.ROYcms_Enterprise();
            bll._Update(model);
           
            Response.Redirect("/administrator/Message.aspx?message=编辑信息成功！&z=yes");
        

        }

        /// <summary>
        /// Enterprise_adds this instance.
        /// </summary>
        void Enterprise_add()
        {

            int user_id = 0;
            if (Fjaspx.Common.Session.Get("user_id") == null)
            {
                Response.Redirect("~/UCenter/login.aspx");
            }
            else
            {
                user_id = Convert.ToInt32(Fjaspx.Common.Session.Get("user_id"));
            }

            string keyword = Fjaspx.Common.input.Htmls(TextBox_keyword.Text);
            string description = Fjaspx.Common.input.Htmls(TextBox_description.Text);

            int classname = int.Parse("00");
            string gs_name = Fjaspx.Common.input.Htmls(txtgs_name.Text);
            string gs_address = Fjaspx.Common.input.Htmls(txtgs_address.Text);
            string gs_tel = Fjaspx.Common.input.Htmls(txtgs_tel.Text);
            string gs_web = Fjaspx.Common.input.Htmls(txtgs_web.Text);
            string gs_email = Fjaspx.Common.input.Htmls(txtgs_email.Text);

            string introduces = Fjaspx.Common.input.Htmls(FCK_1.Value);
            string business_scope = Fjaspx.Common.input.Htmls(FCK_2.Value);
            string contacts_us = Fjaspx.Common.input.Htmls(FCK_3.Value);
            string intelligence_honor = Fjaspx.Common.input.Htmls(FCK_4.Value);

            string enterprise_culture = Fjaspx.Common.input.Htmls(FCK_5.Value);
            string marketing_network = Fjaspx.Common.input.Htmls(FCK_6.Value);
            string other_1 = Fjaspx.Common.input.Htmls(FCK_7.Value);
            string other_2 = Fjaspx.Common.input.Htmls(FCK_8.Value);
            string other_3 = Fjaspx.Common.input.Htmls(FCK_9.Value);
            string other_4 = Fjaspx.Common.input.Htmls(FCK_10.Value);


            Fjaspx.Sys.Model.ROYcms_Enterprise model = new Fjaspx.Sys.Model.ROYcms_Enterprise();
            model.user_id = user_id;
            if (keyword == "")
            {
                model.keyword = gs_name;
            }
            else { model.keyword = keyword; }

            if (description == "")
            {
                model.description = gs_name;
            }
            else { model.description = description; }
            //model.description = description;

            model.classname = classname;

            model.gs_name = gs_name;
            model.gs_tel = gs_tel;
            model.gs_web = gs_web;
            model.gs_email = gs_email;
            model.gs_address = gs_address;


            model.introduces = introduces;
            model.business_scope = business_scope;
            model.intelligence_honor = intelligence_honor;
            model.contacts_us = contacts_us;
            model.enterprise_culture = enterprise_culture;
            model.marketing_network = marketing_network;
            model.other_1 = other_1;
            model.other_2 = other_2;
            model.other_3 = other_3;
            model.other_4 = other_4;


            Fjaspx.Sys.Bll.ROYcms_Enterprise Enterprise_bll = new Fjaspx.Sys.Bll.ROYcms_Enterprise();
            if (Enterprise_bll.Add(model) != 1)
            {
                Response.Redirect("?message=编辑信息成功！&z=yes");
            }
            else
            {
                Response.Redirect("/administrator/Message.aspx?message=异常 失败！&z=no");
            }
        }


    }
}
